在 Ubuntu 22.04 您所在的位置:网站首页 安装ubuntu out of range 在 Ubuntu 22.04

在 Ubuntu 22.04

2024-07-12 14:20| 来源: 网络整理| 查看: 265

在 Ubuntu 22.04|20.04|18.04 上安装和配置 Dnsmasq

本指南将帮助您在 Ubuntu 22.04|20.04|18.04 LTS 上安装和配置 Dnsmasq DNS 服务器。对于 Dnsmasq 的新手来说,Dnsmasq 是一个简单、轻量级、易于使用和管理的 DNS 服务器,支持 Lua 脚本、IPv6、DNSSEC、PXE、BOOTP 和 TFTP 网络启动。它占用空间小,因此适用于资源有限的路由器和防火墙。

Dnsmasq 旨在为中小型网络环境提供 DNS 和可选的 DHCP/TFTP 服务。当它收到 DNS 查询时,它会从本地缓存中应答它们,或者将它们转发到不同的递归 DNS 服务器,该服务器可以是 BIND 或任何其他 DNS 服务器。

我们的博客上提供了 PowerDNS 权威 DNS 服务器的设置:

在 Ubuntu 上安装 PowerDNS 和 PowerDNS-AdminDnsmasq 子系统

Dnsmasq 有三个主要子系统,即:

DNS 子系统:提供 A、AAAA、CNAME 和 PTR 以及 DNSKEY 和 DS 记录的缓存。DHCP子系统:提供对DHCPv4、DHCPv6、BOTP和PXE的支持。您可以使用静态和动态 DHCP 租约,内置只读 TFTP 服务器来支持网络启动。路由器通告子系统:为 IPv6 主机提供基本自动配置第 1 步:安装 Dnsmasq

Ubuntu 18.04+ 附带了 systemd-resolve,您需要禁用它,因为它绑定到端口 53,这将与 Dnsmasq 端口冲突。

运行以下命令禁用已解析的服务:

sudo systemctl disable systemd-resolved sudo systemctl stop systemd-resolved

另外,删除符号链接的 resolv.conf 文件

$ ls -lh /etc/resolv.conf lrwxrwxrwx 1 root root 39 Aug 8 15:52 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf $ sudo unlink /etc/resolv.conf

然后创建新的resolv.conf文件。

echo nameserver 8.8.8.8 | sudo tee /etc/resolv.conf

Dnsmasq 在 apt 存储库中可用,可以通过运行以下命令来轻松安装:

sudo apt update sudo apt install dnsmasq

Dnsmasq 的主要配置文件是 /etc/dnsmasq.conf。通过修改此文件来配置 Dnsmasq。

sudo vim /etc/dnsmasq.conf

这是最小配置

# Listen on this specific port instead of the standard DNS port # (53). Setting this to zero completely disables DNS function, # leaving only DHCP and/or TFTP. port=53 # Never forward plain names (without a dot or domain part) domain-needed # Never forward addresses in the non-routed address spaces. bogus-priv # By default, dnsmasq will send queries to any of the upstream # servers it knows about and tries to favour servers to are known # to be up. Uncommenting this forces dnsmasq to try each query # with each server strictly in the order they appear in # /etc/resolv.conf strict-order # Set this (and domain: see below) if you want to have a domain # automatically added to simple names in a hosts-file. expand-hosts # Set the domain for dnsmasq. this is optional, but if it is set, it # does the following things. # 1) Allows DHCP hosts to have fully qualified domain names, as long # as the domain part matches this setting. # 2) Sets the "domain" DHCP option thereby potentially setting the # domain of all systems configured by DHCP # 3) Provides the domain part for "expand-hosts" #domain=thekelleys.org.uk domain=example.com # Set Listen address listen-address=127.0.0.1 # Set to Server IP for network responses

如果要启用 DNSSEC 验证和缓存,请取消注释

$ sudo dnssec

进行您认为相关的任何其他更改,并在完成后重新启动 dnsmasq:

sudo systemctl restart dnsmasq步骤 2:将 DNS 记录添加到 Dnsmasq

在文件/etc/hosts中添加DNS记录。 Dnsmasq 将使用这些记录回复客户端的查询。

$ sudo vim /etc/hosts 10.1.3.4 server1.mypridomain.com 10.1.4.4 erp.mypridomain.com  192.168.10.2 checkout.mypridomain.com  192.168.4.3 hello.world

添加记录后,您需要重新启动 dnsmasq 服务。

sudo systemctl restart dnsmasq步骤 3:测试 Dnsmasq DNS 功能

要验证 Dnsmasq 是否响应我们添加的记录,请将您的服务器的 DNS 服务器指向 Dnsmasq 服务器。编辑 /etc/network/interfaces 以进行持久配置,或编辑 Ubuntu 服务器上的文件 /etc/netplan/。

由于这是一个测试,我将修改运行时文件 /etc/resolv.conf

$ sudo vim /etc/resolv.conf nameserver 127.0.0.1 nameserver 8.8.8.8

使用挖掘测试:

$ dig A erp.mypridomain.com ; DiG 9.11.3-1ubuntu1.1-Ubuntu A erp.mypridomain.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有